package com.lihao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.dao.CourseDao;
import com.lihao.entity.Course;
import com.lihao.service.intf.CourseService;
import com.lihao.vo.PageVo;
import com.lihao.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.CacheRequest;

/**
 * @ClassName CourseServiceImpl
 * @Description TODO
 * @Author LiHao
 * @Date 2022/11/19 13:19
 * @Version 1.0
 */
@Service
public class CourseServiceImpl implements CourseService {
    @Resource
    private CourseDao dao;

    /**
     * @return R
     * @Author LiHao
     * @Description 添加课程
     * @Date 13:17 2022/11/19
     * @Param [course]
     */
    @Override
    public R add(Course course) {
        if(dao.add(course) > 0){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * @return R
     * @Author LiHao
     * @Description 根据id删除课程
     * @Date 13:17 2022/11/19
     * @Param [id]
     */
    @Override
    public R del(int id) {
        if(dao.del(id) > 0){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * @return R
     * @Author LiHao
     * @Description 更新课程
     * @Date 13:17 2022/11/19
     * @Param [course]
     */
    @Override
    public R update(Course course) {
        if(dao.update(course) > 0){
            return R.ok();
        }
        return R.fail();
    }

    /**
     * @return com.lihao.vo.PageVo
     * @Author LiHao
     * @Description 查询所有课程
     * @Date 13:19 2022/11/19
     * @Param [page, limit]
     */
    @Override
    public PageVo queryPage(int page, int limit) {
        PageHelper.startPage(page,limit);
        PageInfo<Course> pageInfo = new PageInfo<>(dao.selectAll());
        return new PageVo(0,"OK",pageInfo.getTotal(),pageInfo.getList());
    }
}
